package model;

import java.awt.Color;

public class RGBColor {

	private int red;
	private int green;
	private int blue;
	
	public RGBColor(int red, int green, int blue) {
		this.red = red;
		this.green = green;
		this.blue = blue;
	}

	//http://www.rapidtables.com/convert/color/rgb-to-cmyk.htm
		//http://fiji.sc/wiki/index.php/RGB_to_CMYK
		public CMYKColor convertRGBToCMYK(double red, double green, double blue) {
			
			//System.out.println("Methode convertRGBToCMYK IN R:" + red + " G:" + green + " B:" + blue);
			
			CMYKColor cmykToReturn = new CMYKColor(0,0,0,0);
			
			double tempRed = red/255.0;
			double tempGreen = green/255.0;
			double tempBlue = blue/255.0;
			
			cmykToReturn.setBlack(1 - Math.max(tempRed, Math.max(tempGreen, tempBlue)));
			
			//System.out.println("Methode convertRGBToCMYK tmpR:" + tempRed + " tmpG:" + tempGreen + " tmpB:" + tempBlue + " tmpBlack:" + black);
			
			if(cmykToReturn.getBlack() == 1) {
				cmykToReturn.setCyan(0);
				cmykToReturn.setMagenta(0);
				cmykToReturn.setYellow(0);
			} else {		
				cmykToReturn.setCyan((1 - tempRed - cmykToReturn.getBlack())/(1 - cmykToReturn.getBlack()));
				cmykToReturn.setMagenta((1 - tempGreen - cmykToReturn.getBlack())/(1 - cmykToReturn.getBlack()));
				cmykToReturn.setYellow((1 - tempBlue - cmykToReturn.getBlack())/(1 - cmykToReturn.getBlack()));
			}	
			
			//System.out.println("Methode convertRGBToCMYK OUT C:" + cyan + " M:" + magenta + " Y:" + yellow + " K:" + black);
			return cmykToReturn;
		}
		


		public HSVColor convertToHSV(int red, int green, int blue) {
			
			//Code raccourcis... � changer m�me si sa marche..

			//red = red;
			//green = green;
			//blue = blue;
			
			float[] hsv = new float[3];
			
			Color.RGBtoHSB(red,green,blue,hsv);
			
			HSVColor hsvToReturn = new HSVColor(0,0,0);
			
			hsvToReturn.setHue((int) hsv[0]);
			hsvToReturn.setSaturation((int) hsv[1]);
			hsvToReturn.setValue((int) hsv[2]);
			
			
//			v = Math.max(red,green,blue);
//			s = (v-min(red,green,blue))/v;
//			if(red=max&&green=min) h=5+(red-blue)/(red-green);
//			else if(red=max&&B=min) h=1-(red-green)/(red-blue);
//			else if(green=max&&B=min) h=1+(green-red)/(green-blue); 
//			else if(green=max&&red=min) h=3-(green-B)/(green-red); 
//			else if(B=max&&red=min) h=3+(B-green)/(B-red); 
//			else if(B=max&&green=min) h=5-(B-red)/(B-green);
//			h = h * 60;
//			if(h < 0 ) h += 360; (assume h entre 0 et 360)
			
			return hsvToReturn;
		}
	
	public int getRed() {
		return red;
	}

	public void setRed(int red) {
		this.red = red;
	}

	public int getGreen() {
		return green;
	}

	public void setGreen(int green) {
		this.green = green;
	}

	public int getBlue() {
		return blue;
	}

	public void setBlue(int blue) {
		this.blue = blue;
	}
	
	
}
